﻿using System;
using UnityConfiguration.Infrastructure;
using mpu = Microsoft.Practices.Unity;
using UnityConfiguration;
using System.Windows.Markup;

namespace UnityConfiguration
{
    /// <summary>
    /// Configuration element for configuring injection properties.
    /// </summary>
    [ContentProperty("Value")]
    public class Property : InjectionMember, ITypeConfigurationItem
    {
        private InjectionParameterValue _Value;
        private string _PropertyTypeName;
        private string _GenericParameterName;

        /// <summary>
        /// Type of this property.
        /// </summary>
        public string PropertyTypeName {
            get { return _PropertyTypeName; }
            set { _PropertyTypeName = value; }
        }

        /// <summary>
        /// Generic parameter name of this property.
        /// </summary>
        public string GenericParameterName {
            get { return _GenericParameterName; }
            set { _GenericParameterName = value; }
        }

        public IValue Value {
            get { return (IValue)_Value; }
            set { _Value = (InjectionParameterValue)value; }
        }

        /// <summary>
        /// Return the InjectionMember object represented by this configuration
        /// element.
        /// </summary>
        /// <returns>The injection member object.</returns>
        public override mpu.InjectionMember CreateInjectionMember() {
            mpu.InjectionParameterValue param
                = InjectionParameterValueHelper.CreateParameterValue(
                    PropertyTypeName,
                    GenericParameterName,
                    _Value,
                    TypeResolver);

            return new mpu.InjectionProperty(Name, param);
        }
    }
}
